// app.js
App({
  onLaunch() {
    let that = this;
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success (res) {
        console.log(res.code);
        let code = res.code;
        wx.request({
          url: `https://api.weixin.qq.com/sns/jscode2session?appid=wxdc587d438181901a&secret=bc05bc46e2814a339dc82b3f660433bd&js_code=${code}&grant_type=authorization_code`,
          success: (res) => {
            console.log(console.log(res.data.openid));
            that.globalData.openid = res.data.openid
          }
        })
      }
    })

    // 获取系统信息
    const systemInfo = wx.getSystemInfoSync();
    // 胶囊按钮位置信息
    const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
    // 胶囊到状态栏的间距
    this.globalData.menuTopSpace = menuButtonInfo.top - systemInfo.statusBarHeight;
    // 胶囊到右边的间距
    this.globalData.menuRightSpace = systemInfo.screenWidth - menuButtonInfo.right;
    // 胶囊高
    this.globalData.menuHeight = menuButtonInfo.height;
    // 导航栏高度 = 状态栏到胶囊的间距（胶囊上边界坐标 - 状态栏高度） * 2 + 胶囊高度 + 状态栏高度
    this.globalData.navBarHeight = this.globalData.menuTopSpace * 2 + menuButtonInfo.height + systemInfo.statusBarHeight;
    // 状态栏高
    this.globalData.statusBarHeight = systemInfo.statusBarHeight;
  },
  globalData: {
    userInfo: null,
    navBarHeight: 0,
    menuTopSpace: 0,
    menuTopSpace: 0,
    menuHeight: 0,
    statusBarHeight: 0,
    openid: "",
    name: ""
  }
})
